package frontend.user.product.controller;

import java.util.ArrayList;
import java.util.List;

import backend.category.manager.CategoryManager;
import com.opensymphony.xwork2.ActionSupport;
import core.category.model.Category;

public class AjaxRequest extends ActionSupport  
{
	private static final long serialVersionUID = -4008768088656606508L;
	private CategoryManager cm ;
	private Long categoryId ;
	private List<Category> subCategories ;
	
	public AjaxRequest()
	{
		cm = new CategoryManager();
	}
	public String execute() throws Exception
	{	
		return SUCCESS;
	}
	public String getCountry()
	{
		Long categoryId = this.getCategoryId();
		if(categoryId.equals(0L))
		{
			Category world= cm.getCategoryByName("world");
			this.setSubCategories(cm.getSubCategoryByType(world,cm.getCategoryTypeByName("country")));
		}	
		else if(categoryId.equals(-1L))
		{
			this.setSubCategories(new ArrayList<Category>());
		}
		else
		{
			Category category = cm.getCategoryByUuid(categoryId);
			this.setSubCategories(cm.getSubCategoryByType(category,cm.getCategoryTypeByName("country")));
		}
		return SUCCESS;
	}
	public String getState()
	{
		Long categoryId = this.getCategoryId();
		if(categoryId.equals(-1L))
		{
			this.setSubCategories(new ArrayList<Category>());
		}
		else
		{
			Category category = cm.getCategoryByUuid(categoryId);
			this.setSubCategories(cm.getSubCategoryByType(category,cm.getCategoryTypeByName("state")));
		}
		return SUCCESS;
	}
	public String getRegion()
	{
		Long categoryId = this.getCategoryId();
		if(categoryId.equals(-1L))
		{
			this.setSubCategories(new ArrayList<Category>());
		}
		else
		{
			Category category = cm.getCategoryByUuid(categoryId);
			this.setSubCategories(cm.getSubCategoryByType(category,cm.getCategoryTypeByName("region")));
		}
		return SUCCESS;
	}
	public String getCity()
	{
		Long categoryId = this.getCategoryId();
		if(categoryId.equals(-1L))
		{
			this.setSubCategories(new ArrayList<Category>());
		}
		else
		{
			Category category = cm.getCategoryByUuid(categoryId);
			this.setSubCategories(cm.getSubCategoryByType(category,cm.getCategoryTypeByName("city")));
		}
		return SUCCESS;
	}
	public Long getCategoryId() {
		return categoryId;
	}
	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}
	public List<Category> getSubCategories() {
		return subCategories;
	}
	public void setSubCategories(List<Category> subCategories) {
		this.subCategories = subCategories;
	}

}
